<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="/scs_activity/Public/assets/css/amui.all.min.css">
    <link rel="stylesheet" href="/scs_activity/Public/assets/css/app.css">
    <script src="/scs_activity/Public/assets/js/zepto.min.js"></script>
    <script src="/scs_activity/Public/assets/js/amui.min.js"></script>
</head>
<body>
<header id="amz-header" class="head" style="z-index:1000;">
<div class="amz-container am-cf">
    <h1>
        <a href="/landing.jsp">SCS Activity</a>
    </h1>
    <nav>
        <ul class="amz-header-nav am-collapse">
            <li>
                <a href="/scs_activity/index.php/Home/Activity/index">添加活动</a>
            </li>
            <li >
                <a href="/scs_activity/index.php/Home/Activity/regActivity">所有活动</a>
            </li>
            <li>
                <a href="/scs_activity/index.php/Home/Activity/mngActivity">活动管理</a>
            </li>
            <li style="padding-right: 50px;">
                <a href="/scs_activity/index.php/Home/Assign/index">授权管理</a>
            </li>

            <li >
                <a style="padding:0">欢迎,<?php echo ($_SESSION['user']['userid']); ?></a>
            </li>

            <li class="nav-profile need-check">
                <a title="退出登录" href="/scs_activity/index.php/Home/Login/logout">
                    <img width="24" height="24" src="/scs_activity/Public/assets/i/logout.jpg">
                    <span class="am-icon-sign-out"></span>
                </a>
            </li>
        </ul>
    </nav>
</div>
</header>
<div class="amz-banner">
    <div data-am-scrollspy="{animation: 'scale-up', repeat: true}" class="amz-container am-scrollspy-init am-scrollspy-inview am-animation-scale-up" >

        <h1>软件学院活动管理网站</h1>
        <p>期待你的参与，共同管理学生活动.</p>
        <!-- 按钮触发器， 需要指定 target -->
    </div>
</div>
  <?php if($_SESSION['user']['userid']== '' ): ?><script type="text/javascript">
        alert('Login First!!!');
        window.location.href="/scs_activity/index.php/Home/Activity/loginRedirect";
      </script>
      <?php else: endif; ?>
</body>
</html>




<section>
<script type="text/javascript">
function save(){
   
    $.ajax({
        url: '<?php echo U("/Home/Activity/save?type=4");?>',
        type: 'post',
        data: $("#From").serialize(),
    })
    .done(function(data) {
        
        if($("#aid").val()==''){
            $("#aid").val(data);
           
        }
        alert("保存成功");
         console.log("保存成功");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}

function test(){
$("#From").submit();

}
</script>
<form id="From" action='<?php echo U("/Home/Activity/save?type=1");?>' method="post" class="am-form am-form-horizontal"> 
<div class="am-container">
    <div class="am-panel-group" id="accordion">

        <div class="am-panel am-panel-primary">
            <div class="am-panel-hd">
                <h4 class="am-panel-title" data-am-collapse="{parent: '#accordion', target: '#do-not-say-2'}">
                   活动准备
                </h4>
            </div>
            <div id="do-not-say-2" class="am-panel-collapse am-collapse am-in">
                <div class="am-panel-bd">
              
                        <table class="am-table am-table-bd am-table-bdrs am-table-striped">
                           <thead>
                            <tr>
                                <th width="10%">序号</th>
                                <th width="15%">准备时间</th>
                                <th>准备内容</th></tr>
                           </thead>
                            <tbody id="activity_tbody">
                           
                            <?php $__FOR_START_27718__=0;$__FOR_END_27718__=$prepareNum;for($i=$__FOR_START_27718__;$i < $__FOR_END_27718__;$i+=1){ ?><tr>
                                <td><?php echo ($i+1); ?></td>
                                <input type="hidden" name="prid[]" value="<?php echo ($prepare[$i]["prid"]); ?>">
                                <td> <input type="text" name="prtime[]" class="am-form-field datepicker" placeholder="准备时间" value="<?php echo ($prepare[$i]["prtime"]); ?>"></td>
                                <td><input type="text" name="prcontent[]" class="am-form-field" placeholder="准备内容" value="<?php echo ($prepare[$i]["prcontent"]); ?>"></td>
                            </tr><?php } ?>
                          
                            </tbody>
                        </table>

                        <div class="am-form-group">
                            <button type="button" class="am-btn am-btn-default" onclick="add_activity_tbody()">继续添加</button>
                        </div>

                        
                </div>
            </div>
        </div>
        <div class="am-panel am-panel-primary">
            <div class="am-panel-hd">
                <h4 class="am-panel-title" data-am-collapse="{parent: '#accordion', target: '#do-not-say-1'}">
                    活动情况
                </h4>
            </div>
            <div id="do-not-say-1" class=" am-panel-collapse am-collapse">
                <div class="am-panel-bd">
                     <!-- <form class="am-form am-form-horizontal">  -->
                        <input id="aid" type="hidden" name="aid" value="<?php echo ($activity["aid"]); ?>">
                        
                        <div class="am-form-group">
                            <label for="doc-ipt-3" class="col-sm-2 am-form-label">活动主题</label>
                            <div class="col-sm-10">
                                <input type="text" name="atheme" value="<?php echo ($activity["atheme"]); ?>" id="doc-ipt-3" placeholder="活动主题..">
                            </div>
                        </div>

                         <div class="am-form-group">
                            <label class="col-sm-2 am-form-label">活动时间</label>
                            <div class="col-sm-10">
                              <input type="text" name="atime" class="am-form-field datepicker" placeholder="准备时间" value="<?php echo ($activity["atime"]); ?>">
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label class="col-sm-2 am-form-label">活动参与人数</label>
                            <div class="col-sm-10">
                                <input type="text" name="astunumber" value="<?php echo ($activity["astunumber"]); ?>" placeholder="8">
                            </div>
                        </div>



                        <div class="am-form-group">
                            <label  class="col-sm-2 am-form-label">活动新闻</label>
                            <div class="col-sm-10">
                                <textarea name="anews"class="" rows="5" id="doc-ta-1"><?php echo ($activity["anews"]); ?></textarea>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label  class="col-sm-2 am-form-label">活动感受</label>
                            <div class="col-sm-10">
                                <textarea name="aexperience"class="" rows="5" id="doc-ta-1"><?php echo ($activity["aexperience"]); ?></textarea>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label  class="col-sm-2 am-form-label">活动类型</label>
                            <div class="col-sm-10">
                                <select id="atype" name="atype">
                                    <option value="1">选项一...</option>
                                    <option value="2">选项二.....</option>
                                    <option value="3">选项三........</option>
                                </select>
                            </div>
                            <span class="am-form-caret"></span>
                        </div>
                        <div class="am-form-group">
                            
                        </div>
                    <!-- </form>  -->

                </div>
            </div>
        </div>
        <div class="am-panel am-panel-primary">
            <div class="am-panel-hd">
                <h4 class="am-panel-title" data-am-collapse="{parent: '#accordion', target: '#do-not-say-3'}">费用记录</h4>
            </div>
            <div id="do-not-say-3" class="am-panel-collapse am-collapse">
                <div class="am-panel-bd">
                    <table class="am-table am-table-bd am-table-bdrs am-table-striped">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>费用类别</th>
                            <th>费用明细</th>
                            <th>费用用途</th>
                            <th>费用金额</th></tr>
                        </thead>
                        <tbody id="cost_tbody">
                        <?php $__FOR_START_7687__=0;$__FOR_END_7687__=$costNum;for($i=$__FOR_START_7687__;$i < $__FOR_END_7687__;$i+=1){ ?><tr>
                            <td><?php echo ($i+1); ?>
                            <input type="hidden" name="cid[]" value="<?php echo ($cost[$i]["cid"]); ?>">
                            </td>
                            <td><select id="ccategory<?php echo ($i+1); ?>" name="ccategory[]">
                                        <option value="0"></option>
                                        <option value="1">办公用品</option>
                                        <option value="2">耗材</option>
                                        <option value="3">图书费</option>
                                        <option value="4">出租费</option>
                                        <option value="5">停车费</option>
                                        <option value="6">汽油费</option>
                                        <option value="7">餐费</option>
                                        <option value="8">复印费</option>
                                        <option value="9">网费</option>
                                        <option value="10">电话费</option>
                                        <option value="11">其它</option>
                                    </select><span class="am-form-caret"></span></td>
                            <td><input type="" class="am-form-field" placeholder="费用明细" value="<?php echo ($cost[$i]["ccontent"]); ?>"  name="ccontent[]"></td>
                            <td><input type="" class="am-form-field" placeholder="费用用途" value="<?php echo ($cost[$i]["cactual"]); ?>" name="cactual[]"></td>
                            <td><input type="" class="am-form-field" placeholder="费用金额" value="<?php echo ($cost[$i]["cost"]); ?>" name="cost[]"></td>
                        </tr><?php } ?>
                        </tbody>
                    </table>




                    <div class="am-form-group">
                        <button type="button" class="am-btn am-btn-default" onclick="add_cost_tbody()">继续添加</button>
                       
                    </div>
                </div>
            </div>
        </div>
               <div class="am-panel am-panel-primary">
            <div class="am-panel-hd">
                <h4 class="am-panel-title" data-am-collapse="{parent: '#accordion', target: '#do-not-say-4'}">
                    图片上传
                </h4>
            </div>
            <div id="do-not-say-4" class=" am-panel-collapse am-collapse">
                <div class="am-panel-bd">
                   
                     
                    <?php if($havePic == 1 ): ?><div class="am-form-group">
                            <label for="doc-ipt-3" class="col-sm-2 am-form-label">已上传过图片</label>
                        </div>
                    
                    <?php else: ?>
                        <div class="am-form-group">
                            
                            
                            <div class="col-sm-10">
                                <input id="upload" name="file_upload" type="file" multiple="true" value="" />
                                <div id="upload_result">

                                </div>
                            </div>

                            

                            
                        </div><?php endif; ?>

                </div>
            </div>
        </div>
    </div>

</div>
</form>
<div class="am-container"><button type="button" class="am-btn am-btn-primary am-align-right" onclick="test()">提交</button>
 <button type="button" class="am-btn am-btn-default am-align-right" onclick="save()">保存</button></div>


</section>


<div id="topBottomBar">
    <div>
        <a  data-am-smooth-scroll class="am-icon-btn am-icon-arrow-up am-active" title="回到顶部" href="#top"></a>
    </div>
</div>
<br><br><br><br><br><br>
<footer class="footer" style="position:fixed;bottom:0px;width:100%;z-index:10000">
    <p>&copy; 2014 <a target="_blank" href="#">TJUSCS</a> Licensed under <a target="_blank" href="http://scs.tju.edu.cn/">School of Computer Software</a>. Designed by Jungle King.</p>
</footer>
<link rel="stylesheet" href="/scs_activity/Public/assets/css/jquery-ui.min.css">
<link rel="stylesheet" href="/scs_activity/Public/uploadify/uploadify.css">
<script src="/scs_activity/Public/assets/js/jquery.js"></script>
<script src="/scs_activity/Public/assets/js/jquery-ui.min.js"></script>
<script src="/scs_activity/Public/uploadify/jquery.uploadify.js"></script>
<script type="text/javascript">
    function add_cost_tbody(){
        var num=$("#cost_tbody").children("tr").length+1;
        $("#cost_tbody").append("<tr><td>"+num+"</td><td><input type='hidden' name='cid[]'><select id='ccategory"+num+"'  name='ccategory[]'><option value='1'>办公用品</option><option value='2'>耗材</option><option value='3'>图书费</option><option value='4'>出租费</option><option value='5'>停车费</option><option value='6'>汽油费</option><option value='7'>餐费</option><option value='8'>复印费</option><option value='9'>网费</option><option value='10'>电话费</option><option value='11'>其它</option></select><td><input class='am-form-field' placeholder='费用明细' name='ccontent[]'></td><td><input class='am-form-field' placeholder='费用用途' name='cactual[]'></td><td><input class='am-form-field' placeholder='费用金额' name='cost[]'></td></tr>")

    }
    function add_activity_tbody(){
        var num=$("#activity_tbody").children("tr").length+1;
        $("#activity_tbody").append("<tr><td>"+num+"</td><td><input type='hidden' name='prid[]'><input type='text' name='prtime[]' class='am-form-field datepicker' placeholder='准备时间'></td><td><input  type='text' name='prcontent[]' class='am-form-field' placeholder='准备内容'></td></tr>")
        $( ".datepicker" ).datepicker( { dateFormat: "yy-mm-dd" });
     }
    $(function() {
        $( ".datepicker" ).datepicker({ dateFormat: "yy-mm-dd" });
        var num = <?php echo ($costNum); ?>+1;
        $("#atype").val(<?php echo ($activity["atype"]); ?>);
        var cost = <?=json_encode($cost)?>;
        
        
        if(cost!=null){
             for(j=1;j<num;j++) {
                 //alert(cost[j-1].ccategory);
                 // console.log(cost);
                     $("#ccategory"+j).val(cost[j-1].ccategory);
             }
        }
        //var msg = <?=json_encode($msg)?>;
       if(<?php echo ($msg); ?>==2){
            //alert("msg");
        }
        if(<?php echo ($msg); ?>==1){
            alert("您有保存未提交的活动。请提交后进行活动添加");
        }
        if(<?php echo ($msg); ?>==3){
            alert("提交成功");
        }

    });

   
</script>
<script type="text/javascript">

    $(function(){
        
        $("#upload").uploadify({
            //'debug'         :true,
            'height'        : 50,
            'swf'           : '/scs_activity/Public/uploadify/uploadify.swf',
            'uploader'      : '<?php echo U("Activity/savePic");?>',
            'width'         : 120,
            'buttonText'    : '选择图片',
            'auto'          : true,
            'removeCompleted': false,
            'cancelImg'     : '/scs_activity/Public/uploadify/uploadify-cancel.png',
            'multi'         : true,
            'fileTypeExts'  : '*.jpg;*.jpge;*.gif;*.png',
            'fileSizeLimit' : '2MB',
            'uploadLimit'   : 3,
            'progressData'  : 'percentage',
            'queueSizeLimit': 3,
           //不执行默认的onSelect事件
            'overrideEvents' : ['onDialogClose'],
            //服务器端脚本使用的文件对象的名称 $_FILES个['upload']
            'fileObjName':'upload',
            //检测FLASH失败调用
            'onFallback':function(){
                alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");
            },
             //上传到服务器，服务器返回相应信息到data里
            'onUploadSuccess':function(file, data, response){
                var result = $.parseJSON(data);
                console.log(result);
                //console.log(result['savepath']);
                console.log(file['id']);
                var html='<input id="pic_'+file.id +'" type="hidden" value="'+result['savepath']+result['savename']+'" name="path[]" />'
                $("#upload_result").append(html);
                 var cancel=$("#"+file.id + " .cancel a");
                    if (cancel) {
                        cancel.on('click',function () {
                            //在这此处处理...
                            alert('取消');
                            $.ajax({
                                    url: '<?php echo U("/Home/Activity/delPic");?>',
                                    type: 'post',
                                    data: {'savepath':result['savepath'],'savename':result['savename']},
                            })
                            .done(function(data) {
        
                                alert(data);
                                if(data='delok'){
                                /*如果删除成功将隐藏的input删除*/
                                    $("#pic_"+file.id).remove();
                                }
                            })
                            .fail(function() {
                                    console.log("error");
                            })
                            .always(function() {
                                    console.log("complete");
                            });

                            //通过uploadify的settings方式重置上传限制数量
                            $('#upload').uploadify('settings','uploadLimit', 3);
                            //alert($('#upload').uploadify('settings','uploadLimit'));
                            //防止手快多点几次x，把x隐藏掉
                            $(this).hide();
                        });
                    } 
                 //alert(data);
                 //alert(file);
                 //alert(response);
            },
            //返回一个错误，选择文件的时候触发
            'onSelectError':function(file, errorCode, errorMsg){
                switch(errorCode) {
                 case -100:
                    alert("上传的文件数量已经超出系统限制的"+$('#upload').uploadify('settings','queueSizeLimit')+"个文件！");
                    break;
                case -110:
                    alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#upload').uploadify('settings','fileSizeLimit')+"大小！");
                    break;
                case -120:
                    alert("文件 ["+file.name+"] 大小异常！");
                    break;
                case -130:
                    alert("文件 ["+file.name+"] 类型不正确！");
                    break;
                 }

            },
            'onCancel' : function(file) {
            alert('The file ' + file.name + ' was cancelled.');
            }
        });
    });
</script>